/**
 * 虚拟表结构管理--虚拟表结构列表的单例对象
 */
var ProjectTableProperty = {
    id: "ProjectTablePropertyTable",//表格id
    seItem: null,		//选中的第一条记录
    ids: null,//选中的所有记录ids
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ProjectTableProperty.initColumn = function () {
    var columns = [
        {field: 'selectItem'},
        {title: '编号', field: 'id', align: 'center', valign: 'middle', sortable: true},
        {title: '所属表', field: 'table_name', align: 'center', valign: 'middle', sortable: true},
        {title: '中文描述', field: 'CN_name', align: 'center', valign: 'middle', sortable: true},
        {title: '英文名称', field: 'EN_name', align: 'center', valign: 'middle', sortable: true},
        {title: '长度', field: 'length', align: 'center', valign: 'middle', sortable: true},
        {title: '是否可为空', field: 'isNull', align: 'center', valign: 'middle', sortable: true},
        {title: '数据库类型', field: 'db_type', align: 'center', valign: 'middle', sortable: true},
        {title: '代码类型', field: 'code_type', align: 'center', valign: 'middle', sortable: true}]
    return columns;
};

/**
 * 检查是否选中
 */
ProjectTableProperty.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        ProjectTableProperty.seItem = selected[0];
        var ids = "";
        for (var i = 0; i < selected.length; i++) {
            var item = selected[i];
            ids = ids + item.id + ",";
        }
        ids = ids.substring(0, ids.length - 1);
        ProjectTableProperty.ids = ids;
        return true;
    }
};

/**
 * 点击添加虚拟表结构
 */
ProjectTableProperty.openProjectTableProperty = function () {
    var index = layer.open({
        type: 2,
        title: '新建虚拟表结构',
        area: ['1000px', '800px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/projectTableProperty/project_table_property_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看虚拟表结构详情
 */
ProjectTableProperty.openProjectTablePropertyDetail = function () {
    if (this.check()) {
        if (isNaN(ProjectTableProperty.ids)) {
            Feng.info("请不要选择多条记录！");
            return false;
        }
        var index = layer.open({
            type: 2,
            title: '虚拟表结构详情',
            area: ['1000px', '800px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/projectTableProperty/project_table_property_update/' + ProjectTableProperty.seItem.id
        });
        this.layerIndex = index;
    }
};

$(function () {
    var defaultColunms = ProjectTableProperty.initColumn();
    var table = new BSTable(ProjectTableProperty.id, "/projectTableProperty/list", defaultColunms);
    table.setPaginationType("server");
    ProjectTableProperty.table = table.init();
});